package com.cos.shop.web.controller;

import com.cos.shop.common.Const;
import com.cos.shop.common.ResponseResult;
import com.cos.shop.services.ProductServices;
import com.cos.shop.services.impl.ProductServicesImpl;
import com.cos.shop.util.StringUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: COS
 * @time: 2023/5/9 14:36
 * @description:
 */
@WebServlet("/pro")
public class ProductController extends BaseServlet {
    private ProductServices ps = new ProductServicesImpl();

    public String getGoodsById(HttpServletRequest request, HttpServletResponse response) {
        int id = StringUtils.stringToInt(request.getParameter("id"));
        ResponseResult rr = ps.getGoodsById(id);
        request.setAttribute("rr", rr);
        return Const.FORWARD+"goodsDetail.jsp";
    }

    public String getProByTid(HttpServletRequest request, HttpServletResponse response) {
        int typeid = StringUtils.stringToInt(request.getParameter("typeid"));
        int pageNum = StringUtils.stringToInt(request.getParameter("pageNum"));
        //访问业务层处理分页
        ResponseResult rr = ps.getProByTypeId(typeid, pageNum);
        request.setAttribute("rr", rr);
        return Const.FORWARD + "goodsList.jsp";
    }

}
